package com.huanggf.meituan.utils;


import android.util.Log;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateFormatUtil {
    public static final String YMD="yyyy-MM-dd";
    public static final String YMDHMS="yyyy-MM-dd HH:mm:ss";
    public static final String HM="HH:mm";
    private static Calendar calendar = Calendar.getInstance();
    public static String getDate(String formatStr) {
        Date date = new Date();
        SimpleDateFormat format = new SimpleDateFormat(formatStr);
        String now = format.format(date);
        return now;
    }

    public static String dateToStr(Date date, String formatStr) {
        SimpleDateFormat format = new SimpleDateFormat(formatStr);
        return format.format(date);
    }

    public static boolean notEmpty(String s) {
        return s != null && !"".equals(s) && !"null".equals(s);
    }
    public static Date str2Date(String date) {
        if (notEmpty(date)) {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            try {
                return sdf.parse(date);
            } catch (ParseException e) {
                Log.e("ParseException:",e.getMessage());
            }
            return new Date();
        } else {
            return null;
        }
    }
}
